{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Network DEA function example\n",
    "在此示範如何使用Network DEA函式，並顯示執行後的結果。 <BR>\n",
    "    \n",
    "※示範程式碼及csv資料存放於[這裡](https://github.com/wurmen/DEA/tree/master/Functions/network_data%26code)，可自行下載測試。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import network_function  #載入存放Network DEA函式的py檔(在此檔名為\"network_function.py\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 將檔案讀成所需格式\n",
    "- X、Z_input存放於network_data_input.csv中，X位於檔案中的2~3行，Z_input位於4~5行\n",
    "- Y、Z_output存放於network_data_output.csv中，Y位於檔案中第2行，Z_output位於3~4行\n",
    "- 該系統共有3個製程，透過csv2dict_for_network_dea()函式進行讀檔，並回傳得到DMU列表及整體系統與各製程產出投入資料，以及製程數"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU,X,Z_input,p_n=network_function.csv2dict_for_network_dea('network_data_input.csv', v1_range=[2,3], v2_range=[4,5], p_n=3)\n",
    "DMU,Y,Z_output,p_n=network_function.csv2dict_for_network_dea('network_data_output.csv', v1_range=[2,2], v2_range=[3,4], p_n=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 將上述讀檔程式所轉換後的資料放入network DEA函式中，並將權重下限設為1e-11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The efficiency of DMU A:0.523\n",
      "The efficiency and inefficiency of Process 0 for DMU A:1.0000 and 0\n",
      "The efficiency and inefficiency of Process 1 for DMU A:0.7500 and 0.09091\n",
      "The efficiency and inefficiency of Process 2 for DMU A:0.3462 and 0.3864\n",
      "The efficiency of DMU B:0.595\n",
      "The efficiency and inefficiency of Process 0 for DMU B:0.8333 and 0.07143\n",
      "The efficiency and inefficiency of Process 1 for DMU B:1.0000 and 0\n",
      "The efficiency and inefficiency of Process 2 for DMU B:0.5088 and 0.3333\n",
      "The efficiency of DMU C:0.568\n",
      "The efficiency and inefficiency of Process 0 for DMU C:0.5000 and 0.1364\n",
      "The efficiency and inefficiency of Process 1 for DMU C:0.4000 and 0.2727\n",
      "The efficiency and inefficiency of Process 2 for DMU C:0.9474 and 0.02273\n",
      "The efficiency of DMU D:0.482\n",
      "The efficiency and inefficiency of Process 0 for DMU D:0.5625 and 0.125\n",
      "The efficiency and inefficiency of Process 1 for DMU D:0.8000 and 0.07143\n",
      "The efficiency and inefficiency of Process 2 for DMU D:0.3333 and 0.3214\n",
      "The efficiency of DMU E:0.800\n",
      "The efficiency and inefficiency of Process 0 for DMU E:0.8333 and 0.06667\n",
      "The efficiency and inefficiency of Process 1 for DMU E:0.5000 and 0.1333\n",
      "The efficiency and inefficiency of Process 2 for DMU E:1.0000 and 0\n"
     ]
    }
   ],
   "source": [
    "network_function.network(DMU,X,Y,Z_input,Z_output,p_n,var_lb=1e-11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
